package com.feidee.fd.sml.algorithm.ml

import com.feidee.fd.sml.algorithm.component.ml.regression.{GLRegressionComponent, GLRegressionParam}
import com.feidee.fd.sml.algorithm.util.{TestingDataGenerator, ToolClass}
import org.scalatest.FunSuite

/**
  * @Author songhaicheng
  * @Date 2019/3/26 15:17
  * @Description
  * @Reviewer
  */
class GLRegressionComponentSuite extends FunSuite {

  val glr = new GLRegressionComponent
  val paramStr: String =
    """
      |{
      |	'linkPredictionCol': 'linkPrediction',
      |	'family': 'Gaussian',
      |	'link': 'Identity',
      |	'regParam': 0.001
      |}
    """.stripMargin
  val param: GLRegressionParam = glr.parseParam(new ToolClass().encrypt(paramStr))

  test("GeneralizedLinearRegression parameter") {
    assert(param.weightCol == null && "linkPrediction".equals(param.linkPredictionCol) &&
      "Gaussian".equals(param.family) && "Identity".equals(param.link) && "irls".equals(param.solver) &&
      param.maxIter == 25 && param.linkPower.isNaN && param.regParam == 0.001 && param.tol == 1E-6 &&
      param.variancePower == 0.0 && param.fitIntercept)
  }

  test("GeneralizedLinearRegression prediction") {
    val data = TestingDataGenerator.sampleIsotonicRegressionData
    val res = glr.train(param, data).transform(data)
    res.show(false)
    assert(res.schema.size == 4)
  }

}
